package CI.aufgabe2.cip.mynodes;

import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;

public class MyWhileNode extends MyAbstractNode {

	private static final long serialVersionUID = 1L;

	private final MyAbstractNode condition;
	private final MyAbstractNode sequence;

	public MyWhileNode(MyAbstractNode condition, MyAbstractNode sequence) {
		this.condition = condition;
		this.sequence = sequence;
	}

	public MyAbstractNode getCondition() {
		return condition;
	}

	public MyAbstractNode getSequence() {
		return sequence;
	}

	@Override
	public void print() {
		trace("WhileNode ");
		if (condition != null)
			condition.print();

		if (sequence != null)
			sequence.print();

		unindent();
	}
	
	
	
	public AbstractDescr compile(SymbolTable sym) {
		int labelWhile = getNextLabelNumber();
		int labelEnd = getNextLabelNumber();
		write("LABEL, "+ labelWhile);
		condition.compile(sym);
		write("BF, "+labelEnd);
		sequence.compile(sym);
		write("JMP, "+labelWhile);
		write("LABEL, "+labelEnd);
		return null;
	}

}
